# Javascript
## Custom javascript
Drupal javascript behaviors are working out of the box in Wingsuit.
Put your custom javascript code in a `pattern.behavior.js` file inside your pattern.

Wingsuit will load the file automatically and call the `attach` function after component initialization.

<b>Sample behavior file:</b>

```js
Drupal.behaviors.button = {
  attach(context, settings) {
    // Do some stuff
  },
};
```

Wingsuit supports ES6 and compiles (babel) every behavior file to a separate compiled behavior file.
You can find the compiled files in `dist/behaviors/*.behavior.js`.

## Vendor libraries
To embed a 3d party library:

1. Add the 3d party library to your package.json. Run `yarn add library`.
1. Create a javascript file under `source/default/vendorjs/lib.vendor.js` and `@import` the referenced library.

<b>Sample</b>:

```js
import 'regenerator-runtime/runtime';
import 'alpinejs';
```

Wingsuit compiles each vendor file into a separate compiled vendor file, so you can easily embed them in your application.
You can find your vendor file under `dist/app-[type]/vendors/[your-library].js`.

Check out the [webpack asset preset](https://github.com/wingsuit-designsystem/wingsuit/blob/master/packages/core/src/server/presets/assets.ts) for more details!
